<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../../css/aui.css">
    <link rel="stylesheet" type="text/css" href="../../css/aui-slide.css">
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
    <link rel="stylesheet" type="text/css" href="../../font-icon/demo.css">
    <link rel="stylesheet" type="text/css" href="../../font-icon/iconfont.css">
    <script type="text/javascript" src="../../script/api.js"></script>
</head>

<body>
    <div class="aui-content-padded aui-margin-t-10" id="content"></div>
</body>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
    apiready = function() {
        arr = new Array();
        arr1 = new Array();
        arr2 = new Array();
        Mine();

        function Mine() {
            var token = $api.getStorage('token');
            if (token == '') {
                api.alert({
                    msg: '您还未登录，请先登录！'
                })
            }
            var body = {
                categry: 2,
                token: token
            }
            api.ajax({
                url: 'http://www.mk517.com/webApi/youquans.php',
                method: 'post',
                dataType: 'json',
                "headers": {
                    "Content-Type": "application/json"
                },
                data: {
                    body: body
                }
            }, function(ret, err) {
                if (ret) {
                    if (ret.length > 0) {
                        $api.byId('content').innerHTML = '';
                        for (var i = 0; i < ret.length; i++) {
                            data = ret[i];
                            arr.push(data.id);
                            arr2.push(data.tieid);
                            laud = 'laud' + i;
                            (data.post_picture != null && data.post_picture != '') ? (imgAddress = '<div style="width:auto;height:auto;" onclick="openPostInfo(' + data.tieid + ',' + data.id + ')"><img src="' + data.post_picture +
                                '" id="picture1" style="width:100%;height:auto;max-width:100%;max-height:100%;"></div>') : imgAddress = '';
                            $api.byId('content').innerHTML +=
                                '<div class="aui-card-list">' +
                                '<div class="aui-card-list-header aui-card-list-user aui-border-b">' +
                                '<div class="aui-card-list-user-avatar">' +
                                '<img id="post_user_avater" src="' + data.post_user_avater + '" class="aui-img-round" />' +
                                '</div>' +
                                '<div class="aui-card-list-user-name">' +
                                '<div id="post_username">' + data.post_username + '</div>' +
                                '<span class="aui-iconfont aui-icon-close" onclick="cancel(' + i + ');"></span>' +
                                '</div>' +
                                '</div>' +
                                '<div class="aui-card-list-content-padded">' +
                                '<p id="post_goods_content" onclick="openPostInfo(' + data.tieid + ',' + data.id + ')">' + data.post_goods_content + '</p>' +
                                imgAddress +
                                '</div>' +
                                '<div class="aui-card-list-footer aui-border-t">' +
                                '<div id="post_note_count"><i class="aui-iconfont aui-icon-note" id="note" onclick="postComment(' + data.tieid + ',' + data.id + ')">' + data.post_note_count + '</i></div>' +
                                '<div id="post_laud_count"><i id="' + laud + '" class="aui-iconfont aui-icon-laud" onclick="postLaud(' + i + ',' + data.tieid + ')">' + data.post_laud_count + '</i></div>' +
                                '<div id="post_star_count"><i class="aui-iconfont aui-icon-share" onclick="sharePost(' + i + ');"></i>' +
                                '</div>' +
                                '<div id="post_star_count"><i class="icon iconfont icon-hongbao" onclick="postMon(' + data.id + ',' + data.tieid + ')">0</i>' +
                                '</div>' +
                                '</div></div></div>';

                        }
                    }
                } else {
                    //alert(JSON.stringify(err));
                }
            });
        }
        api.addEventListener({
            name: 'publish'
        }, function(ret, err) {
            if (ret) {
                window.location.reload();
            } else {
                // alert(JSON.stringify(err));
            }
        });

        /* 帖子删除功能 */
        window.cancel = function(i) {
                var token = $api.getStorage('token');
                var body = {
                    token: token,
                    tieid: arr2[i]
                };
                api.confirm({
                    msg: '确认删除？',
                    buttons: ['确认', '取消']
                }, function(ret, err) {
                    if (ret) {
                        if (ret.buttonIndex == 1) {
                            api.ajax({
                                url: 'http://www.mk517.com/webApi/deletedynamic.php',
                                method: 'post',
                                dataType: 'json',
                                "headers": {
                                    "Content-Type": "application/json"
                                },
                                data: {
                                    body: body
                                }
                            }, function(ret, err) {
                                if (ret) {
                                    if (ret.info == 'true') {
                                        api.alert({
                                            msg: '删除成功'
                                        }, function(ret, err) {
                                            if (ret) {
                                                Mine();
                                            }
                                        });

                                    }
                                    // alert( JSON.stringify( ret ) );
                                } else {
                                    // alert( JSON.stringify( err ) );
                                }
                            });
                        }
                    } else {
                        //alert( JSON.stringify( err ) );
                    }
                });
            }
            /* 帖子删除功能结束 */

        /* 下拉刷新頁面 */
        api.setRefreshHeaderInfo({
            visible: true,
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err) {
            window.location.reload();
            api.refreshHeaderLoadDone();
        });

    }
</script>

</html>
